const baseUrl= "http://bmj.shningmi.com/";
const glaUrl = "https://akeso.com.cn/api/v5/sessions/";
function request(params){
	var arg = "";
	var token = uni.getStorageSync('token');
	if(!token){
		uni.navigateTo({
			url:"../signin/signin",
			animationType: 'pop-in',
			animationDuration: 300
		})
		return;
	}else{
		params.header.token = token;
	}
	console.log(token,"token");
	if (params && params.data) {
		arg = {
			method: params.method,
			header: params.header,
			data: params.data,
			url: baseUrl + params.url,
		}
	} else {
		arg = {
			method: params.method,
			header: params.header,
			url: baseUrl + params.url,
		}
	}
	return new Promise(function(resolve, reject){
		uni.request({
			...arg,
			success: (res) => {
				// if(res.data.code == 200){
					resolve(res);
				// }
			}
		})
	})
}

function glassesEst(params){
	var arg = "";
	// var token = uni.getStorageSync('token');
	// if(!token){
	// 	uni.navigateTo({
	// 		url:"../signin/signin",
	// 		animationType: 'pop-in',
	// 		animationDuration: 300
	// 	})
	// 	return;
	// }else{
	// 	params.header.token = token;
	// }
	if (params && params.data) {
		arg = {
			method: params.method,
			data: params.data,
			url: glaUrl + params.url,
		}
	} else {
		arg = {
			method: params.method,
			url: glaUrl + params.url,
		}
	}
	return new Promise(function(resolve, reject){
		uni.request({
			...arg,
			success: (res) => {
				// if(res.data.code == 200){
					resolve(res);
				// }
			}
		})
	})
}

export {
	request,
	glassesEst
}